/**
 * validate the form input from donate page
 */

function ltrim(str) { 
	if(str.length==0)
		return(str);
	else {
		var idx=0;
		while(str.charAt(idx).search(/\s/)==0)
			idx++;
		return(str.substr(idx));
	}
}


function rtrim(str) { 
	if(str.length==0)
		return(str);
	else {
		var idx=str.length-1;
		while(str.charAt(idx).search(/\s/)==0)
			idx--;
		return(str.substring(0,idx+1));
	}
}


function trim(str) { 
	return(rtrim(ltrim(str)));
}
	function process(){
		
		var nameObj = document.getElementById("cardName");
		if(trim(nameObj.value).length == 0){
				alert("Name cannot be empty!");
				return;
		}
		
		var amountObj = document.getElementById("amount");
		var amountValue = amountObj.value;
		if(amountValue < 0 || isNaN(amountValue)){
			alert("Amount should be integer!!");
			return;
		}
		
		if( null == amountValue || "" == amountValue)
		{
			alert("Amount cannnot be empty!!");
			return;
		}	
		
		var numObj = document.getElementById("cardNumber");
		var numValue = numObj.value;
		if(numValue.length != 16 || numValue.length==0){
			alert("Credit card number should be 16 digit!!");
			return;
		}
		
		var date1 = document.getElementById("month");
		var date1Value = date1.value;
		if( (date1Value <1) || (date1Value > 12) || date1Value.length==0){
			alert("Invalid credit card Month number or empty number!");
			return;
		}
		
		var date2 = document.getElementById("year");
		var date2Value = date2.value;
		if( date2Value < 10 || date1Value.length==0){
			alert("Invalid credit card year number or empty number!");
			return;
		}
		
		with(document.getElementById("cccheckForm")) {
			method="post";
			action="/ItemManager/creditcardcheck";
			submit();
		}
	}
	function cancel(){
		with(document.getElementById("cccheckForm")) {
			method="post";
			action="/ItemManager/getitem";
			submit();
		}
	}